﻿package cn.poco.pepsi.util.xmlpared;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.xmlpull.v1.XmlPullParser;

import android.util.Xml;
import cn.poco.pepsi.bean.Circle;

public class CircleXmlparse {
	//private final static String TAG = "CityXmlparse";
	private static List<Circle> circles = null;
	private static  Circle circleBean = null;
	
	public static List<Circle> getXml(InputStream inSteam) throws Exception{
		XmlPullParser xmpparse = Xml.newPullParser();   //得到解释器
		xmpparse.setInput(inSteam, "UTF-8");           //设置解释流
		int code = xmpparse.getEventType();            //得到节点信息
		while(code!=XmlPullParser.END_DOCUMENT){
			switch (code) {
			case XmlPullParser.START_DOCUMENT:
				circles = new ArrayList<Circle>();
				break;
			case XmlPullParser.START_TAG:
				if("circle".equals(xmpparse.getName())){
					circleBean = new Circle();
				}
				if(circleBean!=null){
					if("key".equals(xmpparse.getName())){
						String key = xmpparse.nextText();
						circleBean.setKey(key);
					}
					if("name".equals(xmpparse.getName())){
						String name = xmpparse.nextText();
						circleBean.setName(name);
					}
				}
				break;
			case XmlPullParser.END_TAG:
				if("circle".equals(xmpparse.getName())){
					circles.add(circleBean);
					circleBean = null;
				}
				break;
			}	
			code = xmpparse.next();
		}
		inSteam.close();
		return circles;
	}
}
